package com.rc.evcharger.common.type;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Create by Yang on 2019/11/5
 */
public class CardNoData extends BaseType implements DataType {

    public String gunNum;   //枪号

    public String status;  //01 卡号正常可充电 02 余额不足 03 卡不存在 04 卡号被冻结 09 其他原因

    public String account; //卡号余额

    public String obligate = "00 00 00 00";


    public CardNoData() {
    }

    public CardNoData(String gunNum, String status, String account) {
        this.gunNum = gunNum;
        this.status = status;
        this.account = account;
    }

    /**
     * 金额转报文 8.54 <->54 08 00 00
     * @param account
     * @return
     */
    public String parseAccount(BigDecimal account) {
        String s = String.valueOf(account.setScale(2, RoundingMode.CEILING.HALF_UP));
        String substring = s.replace(".", "");

        //补0
        String format = String.format("%08d", Integer.valueOf(substring));

        String accountReport = "";
        for (int i = 0; i < 4; i++) {
            accountReport = format.substring(i * 2, i * 2 + 2) + " " + accountReport;
        }
        String trim = accountReport.trim();

        this.account = trim;

        return this.account;
    }

    public String getGunNum() {
        return gunNum;
    }

    public void setGunNum(String gunNum) {
        this.gunNum = gunNum;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getObligate() {
        return obligate;
    }

    public void setObligate(String obligate) {
        this.obligate = obligate;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        return false;
    }

}
